/*
 *  Blazon: A user datagram protocol re-braodcasting daemon.
 *  base-io.h: Header file for base-io.c
 *
 *  Copyright 2012 Blazon development team
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.

 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef INCLUDED_base_io_h
#define INCLUDED_base_io_h

#define FDE_SOCKET		0x01
#define FDE_LISTEN		0x02	/* using TCP listen() */
#define FDE_BIND		0x04	/* using UDP bind() */
#define FDE_PIPE		0x08
#define FDE_CONNECT		0x10	/* TCP connection (persistent) */
#define FDE_UNKNOWN		0x20	/* TCP connection (persistent) */

#define	FDE_DESCR_SIZE	128		/* max size of fdext description field */

#define DTYPE_GAME	0x01

#define IO_READ			0x01
#define IO_WRITE		0x02
#define IO_ACCEPT		IO_READ
#define IO_BIND			IO_READ|IO_WRITE
#define IO_CONNECT		IO_WRITE

struct _fdext
{
	dlink_node node;
	int fd;
	uint8_t type;
	char *descr;				/* optional fd description */
	bool is_open;
	/*PF *read_handler;
	void *read_data;
	PF *write_handler;
	void *write_data;*/
	void *data;				/* optional ptr to a custom data struct (eg game) */
	uint8_t data_type;
};

typedef struct _fdext fdext_t;

int fd_list_size(void);
extern void fdext_close_all(void);
extern void fdext_close(fdext_t *);
extern fdext_t * bind_udp_socket(const char *, uint16_t);

#endif
